<?php
	$ignore_fields = array('submit','form_name','message_confirm');
	
	function mail_form(){
		global $settings;
		$sender = $settings['contact_info']['contact']['email'];
		$recipients = get_form_recipients();
		$subject = $_POST['form_name'].' submission from '.$settings['contact_info']['domain'];
		$message = get_form_fields();
		mail($recipients, $subject, $message, 'From: '.$sender);
	}
	
	function get_form_recipients(){
		global $settings;
		$recipients = '';
		$iterated_once = false;
		foreach($settings['form_recipients'] as $recipient){
			$recipients .= ($iterated_once==true?',':'').$recipient;
			$iterated_once = true;
		}
		return $recipients;
	}

	function get_form_fields(){
		$form_values = '';
		foreach($_POST as $k=>$v){
			if(!is_ignored($k)){
				if($v != ''){ $form_values .= $k.': '.$v."\r\n"; }
			}
		}
		return($form_values);
	}
	
	function is_ignored($field_name){
		global $ignore_fields;
		$ignore_this = false;
		foreach($ignore_fields as $ignored){
			if($field_name == $ignored){ $ignore_this = true; }
		}
		return($ignore_this);
	}
?>